package com.example.demo.jmeter;

/**
 * @program: mpf-mod-openapi-service
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2022-04-22 10:38
 **/

//import freemarker.template.Configuration;
//import freemarker.template.Template;
//import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

public class FreeMarkerUtils {


    /**
     *
     * TODO
     * <br>
     * @author kangxu2 2016-11-23
     *
     * @param fltFile  flt文件名
     * @param templatePath flt文件路径   src/template
     * @param map 数据集合
     * @return
     */
//    public static String geneFileStr(String fltFile,String templatePath,Object map){
//        Configuration cfg = new Configuration();
//        try ( StringWriter out = new StringWriter()){
//            cfg.setDirectoryForTemplateLoading(new File(templatePath));
//            Template template = cfg.getTemplate(fltFile,"UTF-8");
//            template.setEncoding("UTF-8");
//            template.process(map, out);
//            return out.getBuffer().toString();
//        } catch (Exception e) {
//        }
//        return null;
//    }
//
//    public static String geneFileStr(String fltFile,ClassPathResource pathResource,Object map){
//        Configuration cfg = new Configuration();
//        try ( StringWriter out = new StringWriter()){
////            cfg.setDirectoryForTemplateLoading(new File(templatePath));
//            cfg.setClassLoaderForTemplateLoading(pathResource.getClassLoader(),pathResource.getPath());
//            Template template = cfg.getTemplate(fltFile,"UTF-8");
//            template.setEncoding("UTF-8");
//            template.process(map, out);
//            return out.getBuffer().toString();
//        } catch (Exception e) {
//        }
//        return null;
//    }
//
//    static String GEN_PATH = "D:\\tool\\jmx\\gen";
//    static String RESOURCES_PATH = "E:\\gitlab\\demo\\src\\test\\resources\\jmeter";
//    static String RESOURCES_TEMP = "temp.jmx";
//
//    public static void main(String[] args) throws IOException {
//        HTTPSampler sampler = new HTTPSampler("10.100.20.11", "8000","/cache/redis");
//        // http://10.100.20.11:8000/cache/redis
//        genFileJmx(sampler);
//    }
//
//    private static void genFileJmx(HTTPSampler sampler) throws IOException {
//        String content = geneFileStr(RESOURCES_TEMP, RESOURCES_PATH, sampler);
//        genFile(GEN_PATH,sampler.getPath().replaceAll("/","-")+".jmx",content);
//    }
//
//    public static void genFile(String path,String fileName,String content) throws IOException {
//        String filePath = path + File.separator + fileName;
//        File file = new File(filePath);
//        if (!file.exists()){
//            file.createNewFile();
//        }
//        try(FileWriter fw = new FileWriter(filePath)){
//            fw.write(content);
//        } catch (Exception e){
//            e.printStackTrace();
//        }
//    }

}